-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block Hooks: Add apply_block_hooks_to_content_from_post_object #8212
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Adding a unit test for unhappy paths might be a good idea. When |
@ockham, is this ready for review? |
Not quite yet -- I still need to increase test coverage, and audit other callsites of I won't be able to work on this PR this week, but I'll continue work next week. I hope that works for you time-wise, @Mamaduka? |
Thanks, @ockham! That timeline should be okay for now. We just need to make sure this is merged before Beta 1. |
eafd22b
to
7c9240f
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Switching back to draft mode since I might've encountered a bug while testing. Edit: Figured it out, see below. |
Note that when testing this with a block theme (e.g. TT5), hooked blocks in the This problem will go away once changes to the Post Content block that were made in WordPress/gutenberg#68926 are synced over to Core. You can simulate this by applying this patch.diff --git a/src/wp-includes/blocks/post-content.php b/src/wp-includes/blocks/post-content.php
index e0a06b7217..25be880cc4 100644
--- a/src/wp-includes/blocks/post-content.php
+++ b/src/wp-includes/blocks/post-content.php
@@ -46,33 +46,10 @@ function render_block_core_post_content( $attributes, $content, $block ) {
$content .= wp_link_pages( array( 'echo' => 0 ) );
}
- $ignored_hooked_blocks = get_post_meta( $post_id, '_wp_ignored_hooked_blocks', true );
- if ( ! empty( $ignored_hooked_blocks ) ) {
- $ignored_hooked_blocks = json_decode( $ignored_hooked_blocks, true );
- $attributes['metadata'] = array(
- 'ignoredHookedBlocks' => $ignored_hooked_blocks,
- );
- }
-
- // Wrap in Post Content block so the Block Hooks algorithm can insert blocks
- // that are hooked as first or last child of `core/post-content`.
- $content = get_comment_delimited_block_content(
- 'core/post-content',
- $attributes,
- $content
- );
-
- // We need to remove the `core/post-content` block wrapper after the Block Hooks algorithm,
- // but before `do_blocks` runs, as it would otherwise attempt to render the same block again --
- // thus recursing infinitely.
- add_filter( 'the_content', 'remove_serialized_parent_block', 8 );
-
/** This filter is documented in wp-includes/post-template.php */
$content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) );
unset( $seen_ids[ $post_id ] );
- remove_filter( 'the_content', 'remove_serialized_parent_block', 8 );
-
if ( empty( $content ) ) {
return '';
}
|
Heads-up, I'm thinking to include changes from WordPress/gutenberg#69241 in this. (Should take a couple of minutes only.) |
Done: 970eef5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with reviewing and testing WordPress/gutenberg#69241. In effect, I gained confidence these changes can be safely included here as well. The changes mirror the edits applied in the Gutenberg plugin and they all look good to me.
Port of WordPress/gutenberg#68926 and WordPress/gutenberg#69241.
Fixes
#61074
,#62716
.Trac ticket: https://core.trac.wordpress.org/ticket/62716
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.